/*
 * Created on 2005/4/3
 *
 */
package cliente.applet;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.ImageObserver;

import javax.swing.BoxLayout;
import javax.swing.JCheckBox;

/**
 * @author Lin Yu Ching
 *  
 */
public class PanelBarra extends Panel {

	Applet app;

	public PanelBarra(Applet _app, PanelMapa _mapa) {
		app = _app;
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		Image imgFerramenta = app.getImage(app.getDocumentBase(),
				"cliente/applet/barra_ferramenta.gif");
		add(new BarraCanvas(app, _mapa, imgFerramenta));
		setBounds(0, 0, JanelaApp.APP_W, 25);
	}

}

class BarraCanvas extends Canvas implements ImageObserver, MouseListener {

	Applet app;

	PanelMapa mapa;
	
	Image img;

	public BarraCanvas(Applet _app, PanelMapa _mapa, Image _img) {
		app = _app;
		mapa = _mapa;
		img = _img;
		img.flush();
		setBounds(0, 0, 240, 25);
		setBackground(Color.black);
		addMouseListener(this);
	}

	public void mouseClicked(MouseEvent e) {
		int x = e.getX();
		int y = e.getY();
		
		//System.out.println("posicao: ( " + x + ", " + y + ")");
		if (y>1 && y<20){
			if (x>=4 && x<=22){
				//System.out.println("mexer!!");
				mapa.getCanvas().alteraCentralizacaoAutomatica();
				repaint();
			}
			if (x>=27 && x<=46){
				//System.out.println("ampliar!!");
				mapa.getCanvas().ampliar();
			}
			if (x>=52 && x<=72){
				//System.out.println("diminuir!!");
				mapa.getCanvas().diminuir();
			}
			
		}
		e.consume();
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}

	public void paint(Graphics g) {
		g.drawImage(img, 0, 0, this);
		if (mapa.getCanvas().isCentralizacaoAutomatica()){
			g.setColor(Color.red);
			g.drawLine(5,2,21,19);
			g.drawLine(21,2,5,19);
		}
	}

}